package org.example.beans;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * ThreadLocal作用域Bean - 每个线程创建一个实例
 */
@Component
@Scope("thread")
public class ThreadScopeBean {
    
    private final String instanceId;
    private final String threadName;
    
    public ThreadScopeBean() {
        this.threadName = Thread.currentThread().getName();
        this.instanceId = "ThreadScopeBean-" + threadName + "-" + System.currentTimeMillis() + "-" + this.hashCode();
        System.out.println("在线程 " + threadName + " 中创建ThreadScopeBean实例: " + instanceId);
    }
    
    public String getInstanceId() {
        return instanceId;
    }
    
    public String getThreadName() {
        return threadName;
    }
    
    public void doSomething() {
        System.out.println("ThreadScopeBean在线程 " + Thread.currentThread().getName() + 
                         " 中执行任务，实例ID: " + instanceId);
    }
} 